﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Gallery.MVC.Data;
using Gallery.MVC.Data.DataAccess;
using Gallery.MVC.Services;

namespace Gallery.MVC.Tests
{
    [TestClass]
    public class CatalogTests
    {

        CatalogService catalogService;
        [TestInitialize]
        public void Setup()
        {
            ICatalogRepository rep = new TestCatalogRepository();
            catalogService = new CatalogService(rep);
        }
        
        #region Product Tests
        [TestMethod]
        public void Product_Dicount_Amount_Is_Valid()
        {
            Product p = new Product();

            p.ListPrice = 100;
            p.DiscountPercent = 40;

            Assert.AreEqual(p.DiscountAmount, 40);

        }

        [TestMethod]
        public void Product_Dicount_Price_Is_Valid()
        {
            Product p = new Product();

            p.ListPrice = 100;
            p.DiscountPercent = 40;

            Assert.AreEqual(p.DiscountPrice, 60);

        }
        #endregion

        [TestMethod]
        public void CatalogRepository_Repository_IsNotNull()
        {
            ICatalogRepository rep = new TestCatalogRepository();
            Assert.IsNotNull(rep.GetCategories());
        }

        [TestMethod]
        public void CatalogService_Can_Get_Categories_From_Service()
        { 
            IList<Category> categories =  catalogService.GetCategories();
            Assert.IsTrue(categories.Count> 0 );
        }

        [TestMethod]
        public void CatalogService_Can_Group_Parent_Categories()
        {
            IList<Category> categories = catalogService.GetCategories();
            Assert.AreEqual(2,categories.Count);
        }

        [TestMethod]
        public void CatalogService_Can_Group_SubCategories()
        {
            IList<Category> categories = catalogService.GetCategories();
            Assert.AreEqual(5, categories[0].SubCategories.Count);
        }
    }
}
